#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_3_clicked()
{
    system("/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -m IPython notebook /Users/cyh/Desktop &");
    ui->textBrowser->append("Jupyter notebook is now running at Desktop!\n Don't close this window!\n");
    ui->pushButton_3->setEnabled(false);
}


void MainWindow::on_pushButton_2_clicked()
{
    QProcess process;
    QStringList options;
    options<<"-c"<< "ps -e | grep notebook";
    process.start("/bin/bash",options);
    process.waitForFinished();
//    process.write("grep ps -u cyh notebook");
//    process.waitForFinished();
    QString stdout = process.readAllStandardOutput();
    ui->textBrowser->setText(stdout);
}


void MainWindow::on_pushButton_clicked()
{
    system("kill $(ps -ef|grep notebook | /usr/local/bin/gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')");
    ui->textBrowser->setText("All of jupyter note book has been killed");
    ui->pushButton_3->setEnabled(true);
}

